package com.leyou.item.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.leyou.item.entity.Category;
import org.apache.ibatis.annotations.Select;

import java.util.ArrayList;
import java.util.List;

public interface CategoryMapper extends BaseMapper<Category> {
    @Select("SELECT b.id,b.name,b.parent_id,b.is_parent FROM " +
            "tb_category_brand a ,tb_category b WHERE" +
            "  a.`category_id` = b.id AND a.`brand_id` = #{brandId} ")
    List<Category> findCategoryListByBandId(Long brandId);
    @Select(" SELECT c2.id,c2.name,c2.parent_id,c2.is_parent ,c2.sort\n" +
            "FROM (  \n" +
            "    SELECT\n" +
            "        @r AS _id,  (SELECT @r := parent_id FROM tb_category WHERE id = _id) AS parent_id,  @l := @l -1 AS lvl  \n" +
            "    FROM  \n" +
            "        (SELECT @r := #{id}, @l := 3)AS a,  tb_category AS c  \n" +
            "    WHERE @r <> 0 ) c1  \n" +
            "JOIN tb_category c2  \n" +
            "ON c1._id = c2.id  \n" +
            "ORDER BY c1.lvl")
    List<Category> findCategoryByCid3(Long id);
}
